package com.yuchen.advsdkdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;

import com.yuchen.advsdk.manager.LayoutPollManager;
//import com.yuchen.advsdk.util.LogUtils;

import com.yuchen.advsdk.net.API;
import com.yuchen.advsdk.weight.AdvPercentView;

public class MainActivity extends AppCompatActivity {


    AdvPercentView advPercentView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        API.hostHttp = "http://online.starsaiot.com/cms/requests/advertisementMachine";
//        API.repleaseResourcePathTarget = "http://service.starsaiot.com";
//        API.repleaseResourcePathContent = "http://online.starsaiot.com/cms/resource";

        advPercentView = findViewById(R.id.advview);
//        initAdv();
        LayoutPollManager.getInstance().init(this);
        LayoutPollManager.getInstance().setAuthCallBack(new LayoutPollManager.AuthCallBack() {
            @Override
            public void start() {
//                LogUtils.d("start");
            }

            @Override
            public void success() {
//                LogUtils.d("success");

                try {
                    LayoutPollManager.getInstance().startRun();
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

            @Override
            public void error(String msg) {
//                LogUtils.d("error >> "+msg);
            }
        });
        LayoutPollManager.Config config = LayoutPollManager.getInstance().getConfig();
        config.setDuration(30 * 1000);
        config.setViewModel(AdvPercentView.Model.ON_LINE);
        LayoutPollManager.getInstance().setConfig(config);
        LayoutPollManager.getInstance().setRegistCallBack(new LayoutPollManager.RegistCallBack() {
            @Override
            public void success(long deviceId, String deviceCode) {
//                LogUtils.d("success >> "+deviceId+" "+deviceCode);
                LayoutPollManager.getInstance().bindAdvPercentView(advPercentView);
            }

            @Override
            public void error(String errorMsg) {
//                LogUtils.d("error >> "+errorMsg);
            }
        });
        String appId = "1";
        String appSecret = "2";
        String autoCode = "3";

        LayoutPollManager.getInstance().regist(appId, appSecret, autoCode);


    }



}